<?php
// +----------------------------------------------------------------------
// | zzstudio [ WE CAN DO IT JUST THINK IT ]
// +----------------------------------------------------------------------
// | Copyright (c) 2016 http://www.zzstudio.net All rights reserved.
// +----------------------------------------------------------------------
// | Licensed ( http://www.apache.org/licenses/LICENSE-2.0 )
// +----------------------------------------------------------------------
// | Author: Byron Sampson <xiaobo.sun@gzzstudio.net>
// +----------------------------------------------------------------------
namespace app\common\behavior;

use think\Hook;
use xto\data\dao\ModuleDao;
use think\Facade\Request;


class Hooks
{
    public function run($params=[])
    {  
        // 获取当前模块名称
        $module='';
        //根据当前地址获取模块名称
        $pathinfo=explode('/',request()->server('REQUEST_URI'));
        
       
        foreach ($pathinfo as $key => $value) { 
            if (!empty($value) && !strpos($value, '.php')) {
                $module=$value;
                break;
            }
        } 

        //如果模块为空，则默认调用配置的模块名称
        if (empty($module)) {
            $module=config('default_module');
        }

        //绑定是后台
        if(defined('BIND') && BIND == 'admin') { 
            config('url_controller_layer', 'admin');
            config('url_html_suffix','');
            config('template.view_path', APP_PATH. $module. '/view/admin/');
        }//绑定手机端
        else if(defined('BIND') && BIND == 'wap') {
            config('url_controller_layer', 'wap');
            config('url_html_suffix','');
            config('template.view_path', APP_PATH. $module. '/view/wap/');
        }//默认home
        else if(defined('BIND') && BIND == 'api') {
            config('url_controller_layer', 'api');
            config('url_html_suffix','');
            config('template.view_path', APP_PATH. $module. '/view/api/');
        }//默认home
        else if(defined('BIND') && BIND == 'user') {
            config('url_controller_layer', 'user');
            config('url_html_suffix','');
            config('template.view_path', APP_PATH. $module. '/view/user/');
        }//默认home
        else{
            config('url_controller_layer', 'home');
            config('template.view_path', APP_PATH. $module. '/view/home/');
        } 
    }
}